< previous page page_195 next page >

Page 195
You already know the answer. First, the StandardName and DaylightName fields are defined as the WCHAR typeindicating a 16-bit Unicode character. If the type depended on the entry point, it would have been declared as the TCHAR type, indicating a character whose size depends on the entry point. Second, the GetTimeZoneInformation function in the puzzle was declared as follows:
Private Declare Function GetTimeZoneInformation Lib _
"kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
As you can see, there is no Alias term in the declaration. If the function had two entry points, you would expect to see the term Alias "GetTimeZoneInformationA" in the declaration. The sample program did not raise a "Can't find DLL Entry Point" error, so the GetTimeZoneInformation function entry point actually does exist.
So all we've done so far is prove that the Visual Basic declaration is correct. Yet the sample fails, so there is a problem.
The C++ declaration clearly shows that the StandardName and DaylightName fields are 32-character integers. The Visual Basic declaration is a 32-integer array.
Or is it?
Visual Basic array declarations are zero-based. The field
StandardName(32) As Integer
is a 33-integer array. Change the array bound to 31, and the program will work.
Reading the Names
The StandardName and DaylightName fields are loaded with the Unicode strings. How can you convert them into Visual Basic strings?
There are a number of possible solutions. One of the easiest is based on an interesting feature in Visual Basic that allows you to assign strings to and from arrays.
If you define a string
7017a6ead0e3c4111b47a554df321e9f.gif
Dim timezonename As String
you can assign it directly from the array as follows:
7017a6ead0e3c4111b47a554df321e9f.gif
timezonename = tz.StandardName

 
< previous page page_195 next page >